package com.example.zzl.viewmodel.SearchFragment;


import android.util.Log;

import com.example.zzl.model.bean.SearchFragment.AllBrandData;
import com.example.zzl.model.bean.SearchFragment.Brand;
import com.example.zzl.model.bean.SearchFragment.Cat;
import com.example.zzl.model.bean.SearchFragment.CateData;
import com.example.zzl.model.bean.SearchFragment.Data;
import com.example.zzl.model.bean.SearchFragment.LoadAllBrand;
import com.example.zzl.model.bean.SearchFragment.LoadCateData;
import com.example.zzl.model.bean.SearchFragment.LoadData;
import com.example.zzl.model.bean.SearchFragment.LoadMateData;
import com.example.zzl.model.bean.SearchFragment.Mall;
import com.example.zzl.model.bean.SearchFragment.SearchBrand;
import com.example.zzl.model.bean.SearchFragment.SearchMate;
import com.example.zzl.model.bean.SearchFragment.SearchResultData;
import com.example.zzl.utils.Search.Girls;
import com.example.zzl.view.activity.MainActivity;
import com.example.zzl.view.activity.SearchActivity.AllActivity;
import com.example.zzl.view.activity.SearchActivity.CategoryActivity;
import com.example.zzl.view.activity.SearchActivity.SearchActivity;
import com.example.zzl.view.activity.SearchActivity.SearchResultActivity;

import java.util.ArrayList;
import java.util.Arrays;

/**
 * Created by zhang on 2017/2/8.
 */

public class Classify implements Data{
    private LoadData loadData;
    private LoadAllBrand loadAllBrand;
    private LoadCateData loadCateData;
    private LoadMateData loadMateData;

    public Classify(String url,String type) {
        if(type.equals("SearchAll")) {
            loadAllBrand = new LoadAllBrand(this,url);
            //Log.e("data","Classify");
        }else if(type.equals("Cate")){
            loadCateData = new LoadCateData(this,url);
        }else if(type.equals("Mate")){
            loadMateData = new LoadMateData(this,url);
        }
        else {
            loadData = new LoadData(this, url, type);
        }
    }

    @Override
    public void sendBrand(Brand brand) {
        MainActivity.resultData.brand = brand;
    }

    @Override
    public void sendCat(Cat cat) {
        MainActivity.resultData.cat = cat;
        MainActivity.resultData.cats= (ArrayList<Cat.ListHotTagBean>) cat.getListHotTag();
        MainActivity.handler.sendEmptyMessage(0x101);
    }

    @Override
    public void sendMall(Mall mall) {
        MainActivity.resultData.mall = mall;
        MainActivity.resultData.malls = (ArrayList<Mall.ListHotTagBean>) mall.getListHotTag();
        MainActivity.handler.sendEmptyMessage(0x102);

    }

    @Override
    public void snedSearchResult(ArrayList<SearchBrand.ResultBeanX> results) {
        MainActivity.resultData.results = results;
        //Log.e("data",results.size()+"------");
        MainActivity.handler1.sendEmptyMessage(0x103);

    }

    @Override
    public void sendInfoData(ArrayList<SearchResultData.ResultBean.InfoListBean> infoList) {
        SearchResultActivity.resultData.infoList = infoList;
//        if(infoList.size()==0){
//            SearchResultActivity.handler.sendEmptyMessage(0x1111);
//        }else {
            SearchResultActivity.handler.sendEmptyMessage(0x111);
        //}
    }

    @Override
    public void sendFilterData(ArrayList<SearchResultData.ResultBean.FilterListBean> filterList) {
        SearchResultActivity.resultData.filter = filterList;
//        if(filterList.size() == 0) {
//            SearchResultActivity.handler.sendEmptyMessage(0x1121);
//        }
// else{
            SearchResultActivity.handler.sendEmptyMessage(0x112);
        //}
    }

    @Override
    public void sendAllBrand(ArrayList<AllBrandData> allBrand) {
//        AllActivity.rd.allBrandDatas = allBrand;
        Log.e("data",allBrand.size()+"");
        ArrayList<String> data = new ArrayList<>();
        for (int i = 0; i < allBrand.size(); i++) {
            data.add(allBrand.get(i).getBrandName());
        }
        String [] arr = data.toArray(new String[data.size()]);
        Girls.NAMES = arr;
        AllActivity.handler.sendEmptyMessage(0x201);
    }

    @Override
    public void sendCateData(ArrayList<CateData.ResultBean> cates) {
        CategoryActivity.resultData.cates = cates;
        CategoryActivity.handler.sendEmptyMessage(0x301);

    }

    @Override
    public void sendMateData(ArrayList<SearchMate> mates) {
        SearchActivity.rd.mates = mates;
//        Log.e("data",mates.size()+"");
//        Log.e("data",SearchActivity.rd.malls.size()+"");
        SearchActivity.handler.sendEmptyMessage(0x401);
    }
}
